///我的课程，包括已过期，未过期
import course_api from "../../../repo/api/course_api";

const fetchMyCourseListFromWeb = function () {
  let valid = course_api.getMyValidSubjectList().then(result => result["responseData"].list)
  let invalid = course_api.getMyInvalidSubjectList().then(result => result["responseData"].list)
  return Promise.all([valid, invalid])
    .then((list) => {
      let valid = list[0]
      //未过期
      valid.forEach(e => {
        e.expire = false
        _dealCourseLearnStatus(e)
      })

      let invalid = list[1]
      //已过期
      invalid.forEach(e => {
        e.expire = true
        _dealCourseLearnStatus(e)
      })

      let courseList = []
      courseList.push(...valid)
      courseList.push(...invalid)
      return courseList
    })
}

let _dealCourseLearnStatus = function (e) {
  let subjectInfo = e["subjectInfo"] || {}

  e.isPassed = subjectInfo["subjectExamStatus"] === 1
  if (e.isPassed) {
    e.learningStatus = '已通过'
  } else if (subjectInfo["videoCount"] + subjectInfo["mp3Count"] === subjectInfo["learnMediaCnt"]) {
    e.learningStatus = '已学习'
  } else if (subjectInfo["learnMediaCnt"] > 0) {
    e.learningStatus = '学习中'
  } else {
    e.learningStatus = '待学习'
  }
}
export default {
  fetchMyCourseListFromWeb
}
